﻿using HCD.ValueObjects;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
using RestSharp.Serializers.NewtonsoftJson;
using System.Threading.Tasks;

namespace HCD.DomainServices.Cloud
{
    public class IMManager : EnterpriseDomainServiceBase, IIMManager
    {
        /// <summary>
        /// 读取appsetting.json配置
        /// </summary>
        private readonly IConfiguration _configuration;
        private readonly JsonSerializerSettings _defaultSetting;
        public IMManager(IConfiguration configuration)
        {
            _configuration = configuration;
            _defaultSetting = new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling = NullValueHandling.Ignore
            };
        }
        public async Task SendMsg(IMSendMsgRequest iMRequest)
        {
            var client = new RestClient(_configuration["IM:BaseUrl"]).UseNewtonsoftJson(_defaultSetting);
            var request = new RestRequest("/mdt/message/send").AddJsonBody(iMRequest);
            var responseBase = await client.PostAsync<IMResponseBase>(request);
        }
    }
}
